package sgi.client;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;
import javax.swing.JProgressBar;
import sgi.client.SGIPurchaseImageController.Source;
import sgi.misc.ProgressPanel;

public class SGIPurchaseImageUI extends SGIClientFrame {

	private JPanel contentPane;
	private JPanel contentPaneProgress;
	private SGIPurchaseImageController controller;

	public SGIPurchaseImageUI() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 311, 146);
		contentPane = new JPanel();
		contentPane.setLayout(null);
		setContentPane(contentPane);
		setLocationRelativeTo(null);
		
		JLabel lblAreYouSure = new JLabel("You are about to purchase this image.");
		lblAreYouSure.setBounds(10, 15, 275, 14);
		contentPane.add(lblAreYouSure);
		
		JLabel lblAreYouSure_1 = new JLabel("Are you sure ?");
		lblAreYouSure_1.setBounds(10, 38, 275, 14);
		contentPane.add(lblAreYouSure_1);
		
		JButton btnYes = new JButton("Yes");
		btnYes.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				ProgressPanel prog = new ProgressPanel();
				controller.getUI().removeAll();
				controller.getUI().setContentPane(prog);
				controller.getUI().repaint();
				controller.purchase();			
				}
		});
		btnYes.setBounds(54, 63, 89, 23);
		contentPane.add(btnYes);
		
		JButton btnNo = new JButton("No");
		btnNo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SGIPurchaseImageController.terminate();
				if(controller.getSource() == Source.search)
					try {
						SGISearchArchiveController.create();
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
				else
					try {
						SGIInteractiveMapController.create();
					} catch (IOException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}

			}
		});
		btnNo.setBounds(151, 63, 89, 23);
		contentPane.add(btnNo);
		
		
	}

	public SGIPurchaseImageController getController() {
		return controller;
	}

	public void setController(SGIPurchaseImageController controller) {
		this.controller = controller;
	}
}
